import {
	Request
} from "./request.js"

const PLATFORM_WX = 1; // 微信
const PLATFORM_QQ = 2;
const PLATFORM_ZJ = 3; // 字节
const PLATFORM_BD = 4; // 百度
const PLATFORM_H5 = 5; //
const PLATFORM_OA = 6; // 公众号H5
const PLATFORM_APP = 7; // App

let platfrom = '0';
// #ifdef MP-WEIXIN
platfrom = PLATFORM_WX
// #endif
// #ifdef MP-QQ
platfrom = PLATFORM_QQ
// #endif
// #ifdef MP-TOUTIAO
platfrom = PLATFORM_ZJ
// #endif
// #ifdef MP-BAIDU
platfrom = PLATFORM_BD
// #endif
// #ifdef H5
platfrom = PLATFORM_H5
// #endif

//登录
const login = function(obj) {
	// obj.mark_id=APP_BLIND_BOX;
	const res = Request({
		url: "user/login",
		method: "POST",
		data: obj
	})
	return res
}

const getAuthors = function(page) {
	return Request({
		url: "creators?page=" + page
	})
}

const getHotCreators = function() {
	return Request({
		url: "hot-creators"
	})
}
const getChoiceness = function() {
	return Request({
		url: "choiceness"
	})
}
const getHomeSwiper = function() {
	return Request({
		url: "swiper?place=home"
	})
}
const getCreatorSwiper = function() {
	return Request({
		url: "swiper?place=creator"
	})
}

const getCreatorInfo = function(id) {
	return Request({
		url: "creator?id=" + id
	})
}
const getWorks = function(cid, tid, page) {
	return Request({
		url: `works?cid=${cid}&tid=${tid}&page=${page}`
	})
}
const getDetail = function(id) {
	return Request({
		url: `works-detail?id=${id}`,
		auth: true
	})
}
// 点赞
const like = function(options) {
	return Request({
		url: 'user/like',
		method: "POST",
		data: options.data,
		auth: true
	})
}
// 免广告下载次数
const freetimes = function(options) {
	return Request({
		url: 'user/free-times',
		auth: true
	})
}
// 下载
const download = function(data) {
	return Request({
		url: 'download',
		method: "POST",
		data: data,
		auth: true
	})
}
// 喜欢的
const getLike = function(type) {
	return Request({
		url: 'user/favorites?type=' + type,
		auth: true
	})
}

// 获取配置
const getConfig = function() {
	return Request({
		url: 'config'
	})
}
// 热门标签
const getTags = function() {
	return Request({
		url: 'tags'
	})
}
// 猜你喜欢
const guessLike = function(tag) {
	return Request({
		url: 'guess-like?tag=' + tag
	})
}
const recommendCreators = function(page) {
	return Request({
		url: 'recommend-creators?page=' + page
	})
}
const search = function(word) {
	return Request({
		url: "search?word=" + word
	})
}
const searchByTag = function(tag, page) {
	return Request({
		url: "search-tag?tag=" + tag + "&page=" + page
	})
}
const checkContent = function(data) {
	return Request({
		url: "check-content",
		method: "POST",
		data: data,
	})
}

const feedback = function(data) {
	return Request({
		url: "feedback",
		method: "POST",
		data: data,
	})
}
export default {
	login,
	platfrom,
	getAuthors,
	getHotCreators,
	getChoiceness,
	getHomeSwiper,
	getCreatorSwiper,
	getCreatorInfo,
	getWorks,
	getDetail,
	like,
	getLike,
	freetimes,
	download,
	getConfig,
	getTags,
	search,
	guessLike,
	recommendCreators,
	searchByTag,
	checkContent,
	feedback
}
